<%@page import="com.crm.entity.Opportunity,com.crm.util.Constants,com.crm.entity.Clientdet,com.crm.util.Constants,java.util.List,com.crm.entity.Parts,com.crm.entity.Currency,com.crm.entity.Variables,com.crm.entity.Quotation,com.crm.entity.Business,com.crm.beans.NewQuotVO" %>
<% String srname=(String)request.getAttribute("sourcename");
String supname=(String)request.getAttribute("suppname");
String unitprice=(String)request.getAttribute("uprice");
String terms=(String)request.getAttribute("tnc");
List<Quotation> prequot =(List<Quotation>)request.getAttribute("listquot");
List<Parts> parts =(List<Parts>)request.getAttribute("partlist");
List<NewQuotVO> quotlist =(List<NewQuotVO>)request.getAttribute("newquotlist");
String QuotNo=(String)request.getAttribute("genQuotNo");
Business bus=(Business)request.getAttribute("business");
Variables v=(Variables)request.getAttribute("variables");
Currency currency=(Currency)request.getAttribute("currency");
String quotCurr=request.getAttribute("enqCurrType").toString();
System.out.println("the list of parts"+parts);
System.out.println("This Is NewQuotationDollarRes ");
Clientdet clientdet =(Clientdet)request.getAttribute("client");
Opportunity op=(Opportunity)request.getAttribute("opportunity");
%>
<script type="text/javascript" src="<%=application.getContextPath()%>/js/colResizable-1.3.min.js"></script>	
<script language="JavaScript">
$(function(){
	  $("#quotPartTable").colResizable();
	});
function setDollarAsses(rno,up,edvalue) {
	var up= document.getElementById('unitid'+rno).value;
	var fright= document.getElementById('frightid'+rno).value;
	 document.getElementById('assesid'+rno).value=parseFloat(parseFloat(up)+parseFloat(fright)).toFixed(2);
}
function setDollarTot(rno){	
	var cdec=$("#cdec").is(':checked');
	if(cdec){
		var excessDuty=document.getElementById('assesid'+rno).value;
		var subtot=parseFloat(excessDuty);
		document.getElementById('totid'+rno).value=parseFloat(subtot).toFixed(2);
	}else{
		var excessDuty=document.getElementById('assesid'+rno).value;
		var cst=document.getElementById('bcdid'+rno).value;
		var cstVal=(parseFloat(excessDuty)*parseFloat(cst))/100;
		var subtot=parseFloat(excessDuty)+parseFloat(cstVal);
		document.getElementById('totid'+rno).value=parseFloat(subtot).toFixed(2);	
	}
}
function setUnitPrice(rno){
	var cdec=$("#cdec").is(':checked');
	if(cdec){
		var subtot=document.getElementById('totid'+rno).value;
		 //alert("SubTotal Value Is:"+subtot);
		  var margin=document.getElementById('marginid'+rno).value;
		  var marginVal=(parseFloat(subtot)*parseFloat(margin))/100;
		  //alert("Margin Value Is:"+marginVal);
		 var unitPrice=parseFloat(subtot)+parseFloat(marginVal);
		   document.getElementById('unitprcie'+rno).value=parseFloat(unitPrice).toFixed(2);
	}else{
		var subtot=document.getElementById('totid'+rno).value;
		 //alert("SubTotal Value Is:"+subtot);
		  var margin=document.getElementById('marginid'+rno).value;
		  var marginVal=(parseFloat(subtot)*parseFloat(margin))/100;
		  //alert("Margin Value Is:"+marginVal);
		 var unitPrice=parseFloat(subtot)+parseFloat(marginVal);
		 var vat=(unitPrice*<%=v.getVatPercent()%>)/100;
		   document.getElementById('unitprcie'+rno).value=parseFloat(parseFloat(unitPrice)+parseFloat(vat)).toFixed(2);	
	}
	  }
  function setQuotPrice(rno){
	  var unitPrice=  document.getElementById('unitprcie'+rno).value;
	  var qty=  document.getElementById('reqtyqid'+rno).value;
	  var qprice=parseFloat(unitPrice*qty);
	   document.getElementById('qpriceid'+rno).value=parseFloat(qprice).toFixed(2);
  }
</script>

<div class="boxIFS">
  <table width="100%" >
  <tr>  <td>
  Quotation Currency Is:<%=quotCurr%></td>
  <td align="left" width="50%"> 
 Quotation No .&nbsp; <input name="quotno" type="text" class="form"  style=" width:300px ; color: blue;" id="quotno" value="<%=QuotNo %>" />
</td>
<td align="center" width="50%">
<div id="historyDiv" align="center"  style="color:#F6871F ; font-weight: bold; font-size:16px">Previous Quotation's History</div>
<table style="display:none ; width :350px;"  id="tableId"><tr><td>&nbsp;</td></tr>
<%if(prequot.size()!=0&&prequot!=null){
	for(int i=0;i<prequot.size();i++)
	{%>
<tr><td align="center"><a  class="linkclass" href="#"  onclick="open_new_window('<%=application.getContextPath() %>/newquot/get_history.do?quotid=<%=prequot.get(i).getQuotno()%>')" ><%=prequot.get(i).getQuotno()%></a></td></tr>
<%}
}%>
</table>




<script>

function open_new_window(url) {
	  window.open(url,"some_name","width=500,height=300,left=200,top=10");
	}

    function previewUrl(url,target){
        //use timeout coz mousehover fires several times
        clearTimeout(window.ht);
        window.ht = setTimeout(function(){
            var div = document.getElementById(target);
            div.innerHTML = '<iframe style="width:100%;height:100%;" frameborder="0" src="' + url + '" />';
        },20);      
    }   
</script>

</td>
</tr>

</table>
		<table>
		<tr>
<td align="left"><input id="cdec" type="checkbox" name="cdec" align="left"/>CDEC Required</td>
<td>&nbsp;</td>
</tr>
		</table>
		<%
		if(op.getWarranty()!=null){
		if(op.getWarranty()==true){
			out.println("This Quotation Has Warranty");
		}
		}
		%>
        <table id="quotPartTable" width="100%" border="0" cellpadding="4" cellspacing="1" bgcolor="#C5E4EB">
        <tr>
         
            <td  align="center" valign="middle" background="<%=application.getContextPath() %>/images/table-box.jpg"  style="background-repeat:repeat-x">S.No </td>
            <td  align="center" valign="middle" background="<%=application.getContextPath() %>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">Part No.</td>
            <td  align="center" valign="middle" background="<%=application.getContextPath() %>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF"> Make</td>
            <td  align="center" valign="middle" background="<%=application.getContextPath() %>/images/table-box.jpg"  style="background-repeat:repeat-x bgcolor="#FFFFFF">Description</td>
            <td  align="center" valign="middle" background="<%=application.getContextPath() %>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">Required</td>
            <td  align="center" valign="middle" background="<%=application.getContextPath() %>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">Source</td>
            <td  align="center" valign="middle" background="<%=application.getContextPath() %>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">Supplier</td>
            <td  align="center" valign="middle" background="<%=application.getContextPath() %>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">Unit Value</td>
            <td  align="center" valign="middle" background="<%=application.getContextPath() %>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">Fright(Individual)</td>
            <td  align="center" valign="middle" background="<%=application.getContextPath() %>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">Assesable</td>
            <td  align="center" valign="middle" background="<%=application.getContextPath() %>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">BCD</td>
            <td  align="center" valign="middle" background="<%=application.getContextPath() %>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">Sub Total</td>
            <td  align="center" valign="middle" background="<%=application.getContextPath() %>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">Margin</td>
            <td  align="center" valign="middle" background="<%=application.getContextPath() %>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">UnitPrice</td>
            <td  align="center" valign="middle" background="<%=application.getContextPath() %>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">QuotePrice</td>
            <td  align="center" valign="middle" background="<%=application.getContextPath() %>/images/table-box.jpg"   style="background-repeat:repeat-xbgcolor="#FFFFFF">Delivery</td>
          </tr>
          <%
			for(int i=0;i<quotlist.size();i++){ %>
          <tr>
          
            <td align="center" bgcolor="#FFFFFF"><%=i+1 %></td>
           <%
           String bgcolor=null;
           float curr=quotlist.get(i).getCurrency();
           	if(curr==1 || curr==1.0){
           		bgcolor="#008000";
           	}else{
       
           bgcolor="#FFFFFF";
           } %>
            <td align="left" valign="top" bgcolor="<%=bgcolor%>"><input name="partid<%=i+1%>" type="hidden"  size="5" value="<%=quotlist.get(i).getPartId() %>" /><input name="partno<%=i+1%>" type="text"  class="part" size="5" value="<%=quotlist.get(i).getPartNo() %>" /></td>
            <td align="left" valign="top" bgcolor="#FFFFFF"><input name="make<%=i+1 %>" type="text" size="5"   value="<%=quotlist.get(i).getMake()%>" /></td>
            <td align="left" valign="top" bgcolor="#FFFFFF"><input name="desc<%=i+1 %>" type="text" size="5" value="<%=quotlist.get(i).getDescription()%>"/></td>
            <td align="left" valign="top" bgcolor="#FFFFFF"><input name="required<%=i+1 %>" type="text" id="reqtyqid<%=i+1 %>" size="5" value="<%=quotlist.get(i).getReqQty()%>" /></td>
            <td align="left" valign="top" bgcolor="#FFFFFF"><input name="source<%=i+1 %>" type="text"  size="5" value="<%=quotlist.get(i).getSourceName()%>"/></td>
            <td align="left" valign="top" bgcolor="#FFFFFF"><input name="supplier<%=i+1 %>" type="text" size="5"  value="<%=quotlist.get(i).getSuppName()%>"/></td>
            <td align="left" valign="top" bgcolor="#FFFFFF"><input name="uvalue<%=i+1 %>" id="unitid<%=i+1 %>" type="text" size="5" value="<%=quotlist.get(i).getUnitprice()%>"/></td>
            <td align="left" valign="top" bgcolor="#FFFFFF"><input name="fright<%=i+1 %>"  id="frightid<%=i+1 %>" type="text" size="5"  value="" onblur="setDollarAsses(<%=i+1 %>);"/></td>
            <td align="left" valign="top" bgcolor="#FFFFFF"><input name="assesable<%=i+1 %>" id="assesid<%=i+1%>" type="text" size="5" value=""/></td>
            <td align="left" valign="top" bgcolor="#FFFFFF"><select  name="bcd<%=i+1 %>" id="bcdid<%=i+1 %>" onblur="setDollarTot(<%=i+1 %>);"><option value="2">2</option><option value="5">5%(US)</option><option value="14.5">14.5</option></select></td>
            <td align="left" valign="top" bgcolor="#FFFFFF"><input name="stot<%=i+1 %>" type="text"  id="totid<%=i+1 %>" size="5" value="" /></td>
            <td align="left" valign="top" bgcolor="#FFFFFF"><input name="margin<%=i+1 %>" type="text" id="marginid<%=i+1 %>" size="5" value="" onblur="setUnitPrice(<%=i+1 %>);" placeholder="%"/></td>
           <td align="left" valign="top" bgcolor="#FFFFFF"><input name="unitprice<%=i+1 %>" type="text" id="unitprcie<%=i+1 %>" size="5" value="" onblur="javascript:return setQuotPrice(<%=i+1 %>)"/></td>
            <td align="left" valign="top" bgcolor="#FFFFFF"><input name="quotprice<%=i+1 %>" type="text" id="qpriceid<%=i+1 %>" size="5" value="" /></td>
             <td align="left" valign="top" bgcolor="#FFFFFF"><input name="delivery<%=i+1 %>"  type="text" size="5" value=""/></td>
          </tr>
          <input type="hidden" id="rowcountid" name="rowcount" value="<%=quotlist.size() %>"/>
         <%} %>
            
        </table>
   		<div>
   		</div>
      <div id="terms" style="display: none;" class="box2">
       <textarea rows="10" cols="60" name="termsAndConditions"><%=bus.getTandc() %></textarea>
       </div> 
	    <div class="buttton-main">
<table>
<tr><td>&nbsp;</td></tr>
<tr><td align="right"> <input   type="hidden" value="0" id="tc"/>
 <input  class="button" type="button" value="Terms and Conditions" id="tAndCButton"/>
	    <input  class="button" type="submit" value="Generate Quote" onclick=" javascript :return processFormData();" /></td></tr></table>
	   
	   
	    </div>
	    </div>
	  
      <script type="text/javascript">
      $("#tAndCButton").click(function(){
    	  $("#terms").toggle();
    	  $("#tc").val(1);
      });
      $("#historyDiv").click(function(){
    	  $("#tableId").toggle();
      });
 
      function alertTerms(){
	      var x;
	      var r=confirm("Please Check Terms And Conditions");
	      if (r==true){
	 	     return true;
	        } else{
	       return false;
	        };
	      }
      $(function(){
  		 var client="<%=clientdet.getOrganisation()%>";
  		 var cldiv="<%=clientdet.getDivision()%>";
  		 var cluser="<%=request.getAttribute("user")%>";
  		 $("#enqclient").html("Client Name Is:<span class='cliendet'>"+client +
  		"</span>   &nbsp;&nbsp;&nbsp;&nbsp;  Client Division Is:<span class='cliendet'>"+cldiv+
  		 "</span>    &nbsp;&nbsp;&nbsp;&nbsp;    Client User Is:<span class='cliendet'>"+cluser+"</span>");
  		 $("#enqclient").show();
  	 });
      </script>
   